package com.itheima.controller;

import com.itheima.pojo.Result;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class SessionController {
    @GetMapping("/setSession")
    public Result setSession(HttpSession session){
        session.setAttribute("username","lisi");
        log.info("setSession:{}",session.hashCode());
        return Result.success();
    }

    @GetMapping("/getSession")
    public Result getSession(HttpServletRequest request){
        HttpSession session = request.getSession();
        log.info("getSession:{}",session.hashCode());
        Object username = session.getAttribute("username");
        log.info("username:{}",username);
        return Result.success(username);
    }
}
